package com.lanou.myapp.comic;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.lanou.myapp.R;
import com.lanou.myapp.comic.rankingcomic.RankingComicFragment;
import com.lanou.myapp.comic.recommendedcomic.RecommendedComicFragment;
import com.lanou.myapp.comic.themecomic.ThemeComicFragment;
import com.lanou.myapp.progressdialog.Dialog;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/10.
 */
public class ComicFragment extends Fragment{
    private Context context;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ArrayList<Fragment> list;
    private ComicAdapter adapter;
    private Dialog dialog;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        tabLayout = (TabLayout) getActivity().findViewById(R.id.tabLayout_comic);
        viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager_comic);

        dialog = new Dialog(context,"dfdfd");
        dialog.setTitle("正在加载，请稍后...");
        dialog.show();

        list = new ArrayList<>();
        list.add(new RecommendedComicFragment());
        list.add(new RankingComicFragment());
        list.add(new ThemeComicFragment());

        adapter = new ComicAdapter(getActivity().getSupportFragmentManager(), list,context);
        viewPager.setAdapter(adapter);
        tabLayout.setTabTextColors(Color.BLACK, Color.BLUE);
        tabLayout.setupWithViewPager(viewPager);
        dialog.dismiss();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_comic,null);
        return view;
    }
}
